package com.leetcode.sorts.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: WuPeng
 * @Date: 2021/6/7 11:14 下午
 *
 * 257.二叉树的所有路径
 *
 * 回溯算法
 *
 */
public class BinaryTreePath_257 {

    public List<String> binaryTreePath(TreeNode root){
        List<String> res = new ArrayList<>();
        String path = "";
        builderPath(res, path, root);
        return res;
    }

    private void builderPath(List<String> res, String path, TreeNode node) {
        if (node != null) {
            StringBuilder sb = new StringBuilder(path);
            if (node.left == null && node.right == null) {
                res.add(sb.toString());
            } else {
                sb.append("->");
                builderPath(res, sb.toString(), node.left);
                builderPath(res, sb.toString(), node.right);
            }
        }
    }

    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder("->");
        System.out.println(sb.length());
    }

}
